package com.dinadi.yidi.http.interfaces;

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.IntegralBean;
import com.dinadi.yidi.http.BaseInterface;
import com.dinadi.yidi.http.HttpListener;
import com.dinadi.yidi.http.HttpUrl;
import com.dinadi.yidi.http.ServiceUtil;
import com.dinadi.yidi.ui.MyApplication;
import com.dinadi.yidi.ui.activity.IntegralCenterActivity;
import com.dinadi.yidi.ui.activity.LoginActivity;
import com.dinadi.yidi.ui.view.CommonDialogUtils;
import com.dinadi.yidi.utils.JsonUtil;
import com.dinadi.yidi.utils.ToastUtil;
import com.dinadi.yidi.utils.algorithms.DesUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * author: JiaYu.He
 * Date: 2017/8/2   积分增减共用的interface
 * Time: 14:50
 */
public class IntegralChangeInterface {


    public static String toast;

    public static void IntegralChange(Context context, String userId, String token, String trpe, final String regulation, final String feedback) {
        IntegralBean bean = new IntegralBean();
        bean.setUserId(userId);
        bean.setToken(token);
        bean.setType(trpe);
        bean.setRegulation(regulation);
        CommonInterface creativeProductInterface = new CommonInterface(context, new HttpListener() {
            @Override
            public void OnSuccess(String response) {
                super.OnSuccess(response);
                String errCode = JsonUtil.getFieldValue(response, "errCode");
                String errMsg = JsonUtil.getFieldValue(response, "errMsg");
                if (errCode.equals("0000")) {
                    //"增减积分 增为10 减为-10",
                    String point = JsonUtil.getFieldValue(response, "point");
                    String status = JsonUtil.getFieldValue(response, "status");
                    if (point.equals("0")) {
                        toast = feedback;
                    } else {
                        if (regulation.equals("1")) {
                            toast = "积分+" + point + "\n" + feedback;
                        } else {
                            toast = "积分" + point + "\n" + feedback;
                        }
                    }
                    ToastUtil.showToast(toast);
                } else {
                    ToastUtil.showToast(errMsg);
                }


            }

            @Override
            public void OnFail(String errorResponse) {
                super.OnFail(errorResponse);
                ToastUtil.showToast("加载失败");
            }
        });
        creativeProductInterface.getInterface("16040", JSON.toJSONString(bean));
    }


}

